import Tabs from 'element-plus/es/components/tabs/src/tabs';
import { createStore } from 'vuex'
// import tab from './tab';
type Tabs = {
  id: string;
  menuInfoName: string;
  path: string;
  parentId: string;
  children: Tabs[];
};

export default createStore({
  state: {
    isCollapse:false,
    tabsList:[
      {
        id: '6331b8b9-3719-4dcf-9499-676b964d94ba',
        menuInfoName: '首页',
        path: '/Home',
        parentId:'',
        children:[]
      },
    ],
    breadcrumbList:[]
  },
  mutations: {
    //菜单的展开收起
    collapseMenu(state){
      state.isCollapse=!state.isCollapse
    },
    // 选择菜单
    selectMenu(state,val){
      if (val.path!=='/Home') {
       const index=  state.tabsList.findIndex(item => item.menuInfoName === val.menuInfoName)
      if (index===-1) {
        state.tabsList.push(val);
        }
      }
    },
    // 选择菜单
    selectMenuBreadcrumb(state,val){
      state.breadcrumbList=val;
      // console.log('state.breadcrumbList',state.breadcrumbList);
    },
    // 删除tag
    closeTag(state,item){
      if (item.path!=='/Home') {
        const index=state.tabsList.findIndex(val=>val.menuInfoName ===item.menuInfoName)
        state.tabsList.splice(index,1)
      }
    },
     // 批量删除tag
     BatchDeletionTag(state,item:Tabs[]){
      
      // 提取要删除的 ID
      const idsToDelete = item.map(item => item.id);
      // 过滤出不在 idsToDelete 中的 tab
      state.tabsList = state.tabsList.filter(tab => {
        //保留 path 为 '/Home' 的元素
        if (tab.path==='/Home') {
          return true
        }

        //否则根据id取出
        return !idsToDelete.includes(tab.id)
      });
    },
    //删除全部tag
    closeAll(state){
      state.tabsList = state.tabsList.filter(tab => tab.path === '/Home')
    }
  },
  actions: {
  },
  modules: {
  }
})
